package gui.reports.notices;

import gui.common.*;

import java.io.File;
import java.io.IOException;
import java.util.Observer;
import java.util.Observable;

import reports.builders.HTMLBuilder;
import reports.builders.IBuilder;
import reports.builders.PDFBuilder;
import reports.directors.ExpiredItemReport;
import reports.directors.Notices;

/**
 * Controller class for the notices report view.
 */
public class NoticesReportController extends Controller implements
INoticesReportController {

	/**
	 * Constructor.
	 * 
	 * @param view Reference to the notices report view
	 */	
	public NoticesReportController(IView view) {
		super(view);

		construct();
	}

	//
	// Controller overrides
	//

	/**
	 * Returns a reference to the view for this controller.
	 * 
	 * {@pre None}
	 * 
	 * {@post Returns a reference to the view for this controller.}
	 */
	@Override
	protected INoticesReportView getView() {
		return (INoticesReportView)super.getView();
	}

	/**
	 * Sets the enable/disable state of all components in the controller's view.
	 * A component should be enabled only if the user is currently
	 * allowed to interact with that component.
	 * 
	 * {@pre None}
	 * 
	 * {@post The enable/disable state of all components in the controller's view
	 * have been set appropriately.}
	 */
	@Override
	protected void enableComponents() {
	}

	/**
	 * Loads data into the controller's view.
	 * 
	 *  {@pre None}
	 *  
	 *  {@post The controller has loaded data into its view}
	 */
	@Override
	protected void loadValues() {
	}

	//
	// IExpiredReportController overrides
	//

	/**
	 * This method is called when any of the fields in the
	 * notices report view is changed by the user.
	 */
	@Override
	public void valuesChanged() {
	}

	/**
	 * This method is called when the user clicks the "OK"
	 * button in the notices report view.
	 */
	@Override
	public void display() 
	{
		IBuilder builder;
		if(getView().getFormat()== FileFormat.HTML)
		{
			builder= new HTMLBuilder("Notices");

		}
		else
		{
			builder= new PDFBuilder("Notices");
		}

		Notices reporter= new Notices();
		reporter.build(builder);
		String file=builder.getFilePath();

		try
		{
			java.awt.Desktop.getDesktop().open(new File(file));
		}
		catch (IOException e)
		{
			getView().displayErrorMessage("Could not open pdf file to display report");
			e.printStackTrace();
		}

	}




}

